package com.designPatterns.singleton;

/**
 * 单例模式:立即加载
 * 因静态变量实例在类加载时初始化,故不会出现线程安全问题
 * 基于类的加载机制避免了多线程问题
 * Created by houjinxin on 16/3/5.
 */
public class SingletonInstantLoad {

    private static final SingletonInstantLoad instance = new SingletonInstantLoad();

    private SingletonInstantLoad(){
        System.out.println("我是即时加载的类");
    }

    public static SingletonInstantLoad getInstance(){
        return instance;
    }

    /**
     * 该方法用于测试即使未getInsance 实例也会被创建
     */
    public static void doSomething(){
        System.out.println("干了一些事情");
    }
}
